package com.InvoicingSystem.controller;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.InvoicingSystem.pojo.UserInfo;
import com.InvoicingSystem.service.UserInfoService;
import com.InvoicingSystem.util.Const;



/**
 * @author Administrator
 * @time 2017 上午9:59:49
 * @desc 操作数据库 users表
 */
@Controller
@RequestMapping("/user/")
public class UserInfoController {

	@Autowired
	// 注入 UserInfoService 对象[一定是接口的]
	private UserInfoService userInfoService;

	@RequestMapping("userLogin")
	public String userLogin(String username, String password, HttpSession session, Map<String, Object> map) {

		UserInfo userInfo = userInfoService.findUserLogin(username, password);
		if (null != userInfo) {
			session.setAttribute(Const.USER_INFO, userInfo);
			return "redirect:/index.jsp";
		} else {
			map.put("msg", "账号或者密码错误！");

			return "login";
		}
	}

	@RequestMapping("exit")
	public String exit(HttpSession session) {

		session.removeAttribute("userInfo");

		return "redirect:/login.jsp";
	}

}
